package com.changgou.controller;

import com.changgou.bean.PageResult;
import com.changgou.service.fileService;
import com.changgou.service.syService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.util.Map;

@RestController
@RequestMapping("/syc")
public class BlogImgController {

    @Autowired
    private RedisTemplate redisTemplate;

    @Autowired
    private syService syService;

    @Autowired
    private fileService fileService;

    @RequestMapping("/getblogtp")
    @ResponseBody
    public PageResult getblogtp(@RequestBody Map<String, Object> map){
      return  syService.getblogtp(map);
    }


    @RequestMapping("/addblogtp")
    @ResponseBody
    public boolean addblogtp(@RequestBody Map<String, Object> map){
      return  syService.addblogtp(map);
    }

    @RequestMapping("/delbolgtp")
    @ResponseBody
    public boolean delbolgtp(@RequestBody Map<String, Object> map){
        return  syService.delbolgtp(map);
    }

    @RequestMapping(value = "/uploadFilerePath")
    @ResponseBody
    public String uploadFilerePath(@RequestBody Map<String, Object> map) throws IOException {
//        String ext = request.getParameter("ext");
//        String fname = request.getParameter("name");
////        String aByte = request.getParameter("byte");
////        String substring = aByte.substring(aByte.indexOf(",") + 1);
////        byte[] bytes = Base64.decodeBase64(substring);
////        map.put("aByte",aByte);
//        map.put("fname",fname);
//        map.put("ext",ext);
//        System.out.println(map);
        String fp =  fileService.uploadFilerePath((MultipartFile) map.get("flies"),map);
        System.out.println(fp);
        return fp;
    }


    @RequestMapping("/UserLogin")
    public String UserLogin(){


        return  null;
    }


}
